#!/usr/bin/env python


import docx

def get_docx(file_name):
    d = docx.opendocx(file_name)
    doc = docx.getdocumenttext(d)
    return doc

doc = get_docx(a)
doc = get_docx(r"")
print(doc)  # 输出行数：1075
for d in doc[:-50]:
    if '2.8' in d:
        print('oooooooooo') # 打印前5行




a = r"D:\user\Downloads" + "\\" + "ESG-FODP-CORE-V2.8-新特性列表.doc"

d = []
def a(b):
    c = b + 1
    return d.append(c)
	
	
l1 = []	
def a():
    l = [1 ,2, 3, 4]
    return l1 == l
	
docname = ['EOS-NRPS-CORE_V1.4.SP2-新特性列表.doc','EPM_V6.4.SP1-新特性列表.doc','GIS-ASS-CVS-新特性列表V2.1.doc']
 
version = ['V1.4.SP2', 'V6.4.SP1', 'V2.1']

w = []
e = ['d','o','c','x']
for i in wjm2:
    w.append(i)
    c1 = reduce(lambda x, y:str(x) + str(y),w[-3:])
    if c1 == "doc":
	    del(w[-3:])
	    w.extend(e)
		
name2 = reduce(lambda x, y:str(x)+str(y),w)



name



In [9]: docname
Out[9]:
['EOS-NRPS-CORE_V1.4.SP2-新特性列表.doc',
 'EPM_V6.4.SP1-新特性列表.doc',
 'GIS-ASS-CVS-新特性列表V2.1.doc']

In [10]: version
Out[10]: ['V1.4.SP2', 'V6.4.SP1', 'V2.1']





wjm2 = 'EPM_V6.4.SP1-新特性列表.doc'
banbh = 'V6.4.SP1'
houzm = wjm2.split('.')[-1]#拿后缀名
#wjm3 = wjm2.split('.')#
#mingz1 = wjm3.pop() #去掉文件名的后缀
#fileName=reduce(lambda x, y:str(x)+str(y),wjm3)#合并列表里面的文字
w = []
e = ['d','o','c','x']
for i in wjm2:
    w.append(i)
    c1 = reduce(lambda x, y:str(x) + str(y),w[-3:])
    if c1 == "doc":
      del(w[-3:])
      w.extend(e)		
name2 = reduce(lambda x, y:str(x)+str(y),w)#添加docx之后的文件名

#拼接文件路径和地址名
dress1 = r"D:\user\Downloads"
dress2 = r"D:\user\Downloads" + "\\" + wjm2#初始下载地址的路径+文件名
#转换之后的文件名
name3 = r"D:\user\Downloads" + "\\" + name2

def get_docx(file_name):
    d = docx.opendocx(file_name)
    doc = docx.getdocumenttext(d)
    return doc

if houzm == "doc":
    word = wc.Dispatch("Word.Application")
    doc = word.Documents.Open(dress2)#打开文件
    doc.SaveAs(name3, 12)#保存为docx
    doc.Close()
    word.Quit()
	doc = get_docx(name3)
    #print(doc)  # 
    for d in doc[:-20]:
        if banbh in d:
            print("文件名:%s 版本号:%s  在文档内" % (name2, banbh))
        else:
            #print('NO IN DOCX,PLEASE CHECK')
            pass
elif houzm == "docx":
    doc = get_docx(dress2)
    #print(doc)  #
    for d in doc[:-20]:
        if banbh in d:
            print("文件名:%s 版本号:%s  在文档内" % (wjm2, banbh))
        else:
            #print('NO IN DOCX')
            pass




dictname = str(b[1].text)
dictname = dict(zip(titlelist, contentlist))
content[str(b[1].text)] = dict(zip(titlelist, contentlist))

dictd = {}
a = [1,2,3,4,5,6]
b = ['a','b','c','d','e']
dictname = 'oo'

dictd[dictname] = dict(zip(b, a))


dictd = {}
def w():
    a = [1,2,3,4,5,]
    b = ['a','b','c','d','e']
    dictname = 'oo'
    dictd[dictname] = dict(zip(b, a))
    return dictd[dictname]

dictd = {}
a = [1,2,3,4,5,]
b = ['a','b','c','d','e']
dictname = 'oo'
dictname2 = 'op'
dictd[dictname] = dict(zip(b, a))
dictd[dictname2] = dict(zip(a, b))


wjml = []
for i in wjm:
    wjml.append(i)

wjml 
bb =re.match( r'(.*\.doc) |(.*\.docx).*', wjm, re.M|re.I)

bb =re.match( r'(.*\.doc) .*', wjm, re.M|re.I)
bb.group(1)


wjm = 'SCS-OMS-CORE V5.1.SP1 新特性列表.docx   2019-01-29 15:06:56   [77.03 KB]'
try:
    #wjm = brower.find_element_by_id("divFileGroup11").text
    wjm1 = re.match( r'(.*\.docx)', wjm, re.M|re.I)
    wjm2 = wjm1.group(1)
    print(wjm2)
    #brower.find_element_by_link_text(wjm2).click()
except:
    #wjm = brower.find_element_by_id("divFileGroup11").text
    wjm1 = re.match( r'(.*\.doc)', wjm, re.M|re.I)
    wjm2 = wjm1.group(1)
    print(wjm2)
    #brower.find_element_by_link_text(wjm2).click()










